package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;


    @PostMapping
    public R save(@RequestBody DishDto dishDto){
        R r = dishService.saveWithDishFlavor(dishDto);
        return r;
    }


    @GetMapping("/page")
    public R page(Integer page,Integer pageSize,String name){
        R r = dishService.findDish(page,pageSize,name);
        return r;
    }

    @GetMapping("/{id}")
    public R getByIdWithFlavor(@PathVariable Long id){
        R r = dishService.getByIdWithFlavor(id);
        return r;
    }

    @PutMapping
    public R modifyByIdWithFlavor(@RequestBody DishDto dishDto){

        R r = dishService.modifyByIdWithFlavor(dishDto);
        return r;
    }

    @DeleteMapping
    public R removeByIdsWithFlavor(Long[] ids){
        R r = dishService.removeByIdsWithFlavor(ids);
        return r;
    }

    @PostMapping("/status/{status}")
    public R modifyByStatus(@PathVariable Integer status, Long[] ids){
        R r = dishService.modifyByStatus(status,ids);
        return r;
    }



    @GetMapping("/list")
    private R findDishByCategroyId(Dish dish){
        R r = dishService.findDishByCategroyId(dish);
        return r;
    }

}
